<?php

namespace app\common\model;

/**
 * Class ConsultingServer
 * @package app\model
 * @property int $id
 * @property int $userId
 * @property int $serverType
 * @property string $name
 * @property int $isChatFreely
 * @property int $chatFreelyDuration
 * @property int $questionsNum
 * @property int $isShowCallTel
 * @property int $showCallTelDuration
 * @property float $showPrice
 * @property float $price
 * @property float $subsidy
 * @property string $icon
 * @property string $desc1
 * @property string $desc2
 * @property string $desc3
 * @property int $updated
 * @property int $created
 * @property int $deleted
 * @property string $iconImg
 * @property int $maxTimes
 * @property int $recommendServerId
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class ConsultingServer extends \app\common\model\BaseModel implements ShareableLawyerInterface
{
    // 服务类型 1自定义服务 2免费咨询 3极速咨询 4畅聊 5电话咨询 6找律师
    const CUSTOM = 1;
    const FREE = 2;
    const QUICK = 3;
    const FREELY = 4;
    const PHONE = 5;

    protected $name = 'ConsultingServer';

    public function recommendServer()
    {
        return $this->hasOne(ConsultingServer::class, 'id', 'recommendServerId');
    }

    // 图标
    public function getIconImgAttr($value, $data)
    {
        return image_url($data['icon'] ?? '', 'min');
    }

    // 统计图标
    public function getDataIconImgAttr($value, $data)
    {
        return image_url($data['dataIcon'] ?? '', 'min');
    }

    public function getQuestionsNumStrAttr($value, $data)
    {
        if ($data['isChatFreely'] == 1) {
            return '赠送' . humanized_time_length($data['chatFreelyDuration'] * 3600) . '畅聊';
        } elseif ($data['questionsNum'] > 0) {
            return '赠送' . $data['questionsNum'] . '次聊天';
        } else {
            return '';
        }
    }

    /**
     * 1对1
     * @return \think\model\relation\HasOne
     */
    //    public function one(){
    //        return $this->hasOne( Test1::class, 'Test1表中的键', 'MemberAskServer表中的键');
    //    }

    /**
     * 1对多
     * @return \think\model\relation\HasMany
     */
    //    public function many(){
    //        return $this->hasMany( Test1::class, 'Test1表中的键', 'MemberAskServer表中的键');
    //    }

    /**
     * 多对多
     * @return \think\model\relation\BelongsToMany
     */
    //    public function belongs(){
    //        return $this->belongsToMany( Test1::class, '中间表', '中间表中Test1的键', '中间表中MemberAskServer的键');
    //    }
}
